window.addEventListener("load", function () {
	//回到顶部功能板块
	// 获取相关节点
	$(".iconfont");

	this.window.addEventListener("scroll", function () {
		if (this.scrollY > 1000) {
			$(".iconfont").style.display = "block";
		} else {
			$(".iconfont").style.display = "none";
		}
	});
	//给节点绑定点击事件，点击时实现回到顶部功能；
	$(".iconfont").addEventListener("click", function () {
		window.scrollTo({
			top: 0,
			left: 0,
			behavior: "smooth",
		});
	});

	//这里是行业巨头轮播图的js代码
	//获取到相关节点
	const arr = $(".leader-picTxt");
	//先让第一张图片显示
	arr[0].style.opacity = 1; // 在全局设置了第一张图片的opacity属性，不会被下方的周期定时器的局部属性覆盖，这里提升了第一张图片（opacity）的量级
	// 声明一个变量并赋值为1，要让周期定时器过3s跳转到第二张图就要从第二张图开始算，如果从第一张开始算，那么第一张跳到第二张图的时间就是6s
	let index = 1;
	// // 设置间隔3s的周期定时器，开启周期循环
	this.window.setInterval(function () {
		//在css中设置了opacity=0；js中第一张图的opacity=1，所以此时只会显示第一张图，其余不显示，开启周期循环时所有图片开始循环，所以第一步先遍历所有元素节点，让其opacity=0；（js从上到下执行代码，在这之前已经让第一张图片的opacity=1，所以不会掩盖住第一张图的opacity属性，因为这里是局部变量）
		//
		arr.forEach(function (v) {
			v.style.opacity = 0;
		});
		//通过设置的索引显示对应的内容
		arr[index].style.opacity = "1";
		//上方显示完成后让索引++此时相当于index+1，成为了新的索引值
		index++;
		//判断，当索引值大于等于数组的长度时让索引值变成0回复到最初的状态
		if (index >= arr.length) {
			index = 0;
		}
	}, 3000);

	//海量API板块的js代码
	// console.log($(".icon"));
	$(".icon").forEach(function (v) {
		// console.log(v);
		//   声明一个变量保存最开始的路径
		let oldUrl = v.firstElementChild.src;
		// 给icon绑定鼠标移入事件
		v.addEventListener("mouseover", function () {
			// 移入时背景颜色变为蓝色
			this.style.backgroundColor = "#2f7ee9";
			// 移入时字体颜色变为白色
			this.style.color = "#fff";
			// 声明一个变量接一下原先的路径
			let strUrl = this.firstElementChild.src;

			// console.log(strUrl.lastIndexOf(".")); // 下标是79
			strUrl.lastIndexOf(".");
			strUrl.slice(strUrl.lastIndexOf("."));
			// console.log(strUrl.slice(strUrl.lastIndexOf("."))); //.svg
			let imgUrl2 = strUrl.replace(
				strUrl.slice(strUrl.lastIndexOf(".")),
				"-c.svg"
			);

			// imgUrl2; //新的图片路径
			this.firstElementChild.src = `${imgUrl2}`;
		});
		// 给icon绑定鼠标移出事件
		v.addEventListener("mouseout", function () {
			this.style.backgroundColor = "#fff";
			this.style.color = "#000";
			this.firstElementChild.src = oldUrl;
		});
	});
	// 这里是Swiper插件的js代码
	var mySwiper = new Swiper(".swiper", {
		autoplay: true, //可选选项，自动滑动
		pagination: {
			el: ".swiper-pagination",
		},
	});
	//如果你初始化时没有定义Swiper实例，后面也可以通过Swiper的HTML元素来获取该实例
	// new Swiper(".swiper");
	// var mySwiper = document.querySelector(".swiper").swiper;
	// mySwiper.slideNext();
});

window.addEventListener("load", function () {
	//首页导航栏板块

	const nodeList = $(".navgit");
	nodeList.forEach(function (v) {
		v.addEventListener("click", function () {
			nodeList.forEach(function (value) {
				value.className = "";
			});

			v.className = "active";
		});
	});

	//首页注册功能
	//    const nodeList = $("")
});

//登录注册板块
const inputNode = $(".verify1"); // 获取到用户名输入框的元素节点

//用户名输入框获得焦点时，errorName隐藏
inputNode.addEventListener("focus", function () {
	$(".errorName").style.visibility = "hidden";
});
//用户名输入框失去焦点时判断其长度，从而判断errorName是否隐藏
inputNode.addEventListener("blur", function () {
	let inputStr = `${this.value}`;
	console.log(inputStr.length);
	if (inputStr.length < 6 || inputStr.length > 12) {
		$(".errorName").style.visibility = "visible";
	}
});

//手机号输入框

$(".verify2").addEventListener("focus", function () {
	$(".errorPhoNum").style.visibility = "hidden";
});
$(".verify2").addEventListener("blur", function () {
	let phoNumStr = `${this.value}`;
	if (phoNumStr.length !== 11) {
		$(".errorPhoNum").style.visibility = "visible";
	}
});

//密码框
$(".verify3").addEventListener("focus", function () {
	$(".errorPassword").style.visibility = "hidden";
});
$(".verify3").addEventListener("blur", function () {
	let passwardStr = `${this.value}`;
	if (passwardStr.length < 6 || passwardStr.length > 12) {
		$(".errorPassword").style.visibility = "visible";
	}
});

//头部导航栏注册按钮
window.addEventListener("load", function () {
	$(".registBtn").addEventListener("click", function () {
		$(".model").style.visibility = "visible";
		$(".regis-plate").style.visibility = "visible";
		$(".regis-cont").style.visibility = "visible";
		$(".formCont").style.visibility = "visible";
		$(".errorName").style.visibility = "visible";
		$(".errorPhoNum").style.visibility = "visible";
		$(".errorPassword").style.visibility = "visible";
		$("body").style.overflow = "hidden"
	});

	$(".RegNow").addEventListener("click", function () {
		$(".model").style.visibility = "hidden";
		$(".regis-plate").style.visibility = "hidden";
		$(".regis-cont").style.visibility = "hidden";
		$(".formCont").style.visibility = "hidden";
		$(".errorName").style.visibility = "hidden";	
		$(".errorPhoNum").style.visibility = "hidden";
		$(".errorPassword").style.visibility = "hidden";
		$("body").style.overflow = "auto"
	});
});
// 登录界面跳转;
window.addEventListener("load", function () {
	$(".LoginScreen").style.visibility = "hidden";
	// 注册模态框头部下的按钮跳转至登录界面;
	$(".logined").addEventListener("click", function () {
		// 登录界面显示
		$(".LoginScreen").style.visibility = "visible";
		document.body.style.overflow = "hidden";
	});

	// 登录界面登录立即注册按钮按下跳转至注册界面;
	$(".regisEd .reSon").addEventListener("click", function () {
		//登录界面隐藏
		$(".LoginScreen").style.visibility = "hidden";
		$(".model").style.visibility = "visible";
		$(".regis-plate").style.visibility = "visible";
		$(".errorName").style.visibility = "visible";
		$(".errorPhoNum").style.visibility = "visible";
		$(".errorPassword").style.visibility = "visible";
		$(".formCont").style.visibility = "visible";
	});

	//首页登录按钮按下显示登录界面
	$(".Glooe").addEventListener("click", function () {
		// 登录界面显示
		$(".LoginScreen").style.visibility = "visible";
		$("body").style.overflow = "hidden"
	});

	// 注册模态框头部下的按钮已有源码账号跳转至登录界面
	$(".HaveAccount").addEventListener("click", function () {
		// 登录界面显示
		$(".LoginScreen").style.visibility = "visible";
	});

	//登录界面登录按钮按下让自己消失
	$(".logining").addEventListener("click", function () {
		$(".LoginScreen").style.visibility = "hidden";
		$(".model").style.visibility = "hidden";
		$(".regis-plate").style.visibility = "hidden";
		$(".regis-cont").style.visibility = "hidden";
		$(".formCont").style.visibility = "hidden";
		$(".errorName").style.visibility = "hidden";
		$(".errorPhoNum").style.visibility = "hidden";
		$(".errorPassword").style.visibility = "hidden";
		$("body").style.overflow = "auto"
	});
	




	// 广告区立即注册
	
	console.log($(".AdverBtn"));
	$(".AdverBtn").addEventListener("click", function () {

		$(".model").style.visibility = "visible";
		$(".regis-plate").style.visibility = "visible";
		$(".regis-cont").style.visibility = "visible";
		$(".formCont").style.visibility = "visible";
		$(".errorName").style.visibility = "visible";
		$(".errorPhoNum").style.visibility = "visible";
		$(".errorPassword").style.visibility = "visible";
		$("body").style.overflow = "hidden"

	})

	
	
	$(".RegNow").addEventListener("click", function () {
		
		$("body").style.overflow = "auto"

	})




	
});
window.addEventListener("load", function () {
	//登录界面扫码登录账号登录的二级菜单
	const loginNode = $(".UserLgin");
	const formNodes = $(".formSubmit");
	


	loginNode.forEach(function (v , i) {
		
		v.addEventListener("click", function () {
			
			loginNode.forEach(function (value,index) {
				
				value.classList.remove("active")
				formNodes[index].classList.remove("on");
				

			})
			this.classList.add("active");
			formNodes[i].classList.add("on");
			  

		})

	})
	// 扫码界面注册按钮点击让自己消失,显示注册界面
	const regisNode = $(".registerNow");
	regisNode.forEach(function (v) {
		
		v.addEventListener("click", function () {
			 

			$(".LoginScreen").style.visibility = "hidden";
			$(".model").style.visibility = "visible";
			$(".regis-plate").style.visibility = "visible";
			$(".regis-cont").style.visibility = "visible";
			$(".formCont").style.visibility = "visible";
			$(".errorName").style.visibility = "visible";
			$(".errorPhoNum").style.visibility = "visible";
			$(".errorPassword").style.visibility = "visible";
			$("body").style.overflow = "hidden"


		})

	})

    










})


